<?php

require_once 'Zend/View.php';
require_once 'Zend/Controller/Front.php';

class Core_Widget_Form extends Core_Widget_Abstract
{
	protected function init()
	{
    $this->getView()->formid = get_class($this);
	}
	public function isProcess()
	{
		return ($this->getRequest()->getPost('formid') == get_class($this));
	}
	
  public function getData($index = null)
  {
		if($index === null)
			return $this->getView()->data;
		
    return @$this->getView()->data->{$index};
  }
  
  public function setData($data)
  {
		$this->getView()->data = $data;
		return $this;
  }
  
  public function clearData()
  {
		unset($this->getView()->data);
  	return $this;
  }
  
  public function hasMessage($index = null)
  {
    $messages = $this->getView()->message;

    if($index === null)
    {
      return empty($messages)?false:true;
    }
    return empty($messages[$index])?false:true;
  }

  public function getMessage($index = null)
  {
    return ($index === null)?$this->getView()->message:@$this->getView()->message[$index];
  }
  
  public function setMessage($key, $val = null)
  {
    $stores   = $this->getView()->message;
    $messages = is_array($key)?$key:array($key=>$val);
    
    foreach($messages as $k=>$v)
      $stores[$k] = $v;
    
    $this->getView()->message = $stores;
    return $this;
  }
  
  public function clearMessage()
  {
   $this->getView()->message = array(); 
   return $this;
  }
}